import request from '@/utils/request'

// api地址
const api = {
  userInfo: '/app/customer/info',
  assets: '/app/customer/assets',
  bindMobile: 'user/bindMobile',
  personal: 'user/personal',
  uploadImage: '/app/customer/uploadHeadImage'
}

// 当前登录的用户信息
export const info = (param, option) => {
  const options = {
    isPrompt: true, //（默认 true 说明：本接口抛出的错误是否提示）
    load: true, //（默认 true 说明：本接口是否提示加载动画）
    ...option
  }
  return request.get(api.userInfo, param, options)
}

// 账户资产
export const assets = (param, option) => {
  return request.get(api.assets, param, option)
}

// 绑定手机号
export const bindMobile = (data, option) => {
  return request.post(api.bindMobile, data, option)
}

// 修改个人信息（头像昵称）
export const personal = (data, option) => {
  return request.post(api.personal, data, option)
}

// 图片上传
export const image = (files) => {
  // 文件上传大小, 2M
  const maxSize = 1024 * 1024 * 2
  // 执行上传
  return new Promise((resolve, reject) => {
    request.urlFileUpload({url:api.uploadImage, files:files})
      .then(result => {
		  if (result) {
			  resolve(result.map(item => item.id), result)
		  } else {
			  resolve(result)
		  }
	
		  })
      .catch(reject)
  })
}